from access.core.codesnippetgenerator import CodeSnippetGenerator
from access.core.codesnippetpattern import CodeSnippetPattern
import unittest

class CodeSnippetGeneratorTest(unittest.TestCase):
  def testGenerateFromPatternWithoutContext(self):
    code_snippet_pattern = CodeSnippetPattern \
    (ID_pattern = 'some id',
     value_pattern = 'some value')
    
    generator = CodeSnippetGenerator()
    infos = generator.Generate(code_snippet_pattern)
    self.assertEqual(1,
                     len(infos),
                     'Expected one ID info. Actual: %s' % len(infos))
    self.assertEqual('some id', infos[0].ID)
    self.assertEqual('some value', infos[0].value)

  def testGenerateFromPattern(self):
    code_snippet_pattern = CodeSnippetPattern \
    (ID_pattern = 'some id using {{token}}',
     value_pattern = 'some value using {{token}}',
     token = ['a', 'b'])
    
    generator = CodeSnippetGenerator()
    infos = generator.Generate(code_snippet_pattern)
    self.assertEqual(2,
                     len(infos),
                     'Expected one ID info. Actual: %s' % len(infos))
    self.assertEqual('some id using a', infos[0].ID)
    self.assertEqual('some value using a', infos[0].value)
    self.assertEqual('some id using b', infos[1].ID)
    self.assertEqual('some value using b', infos[1].value)
